package com.cn.jinl.controller;


import com.cn.jinl.api.IOrderService;
import com.cn.jinl.api.IProductStorageRelateService;
import com.cn.jinl.api.IProductStorageService;
import com.cn.jinl.domain.ProductStorageOutRelate;
import com.cn.jinl.domain.ProductStorageRelate;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/psRelate")
public class ProductStorageRelateController {
    @Autowired
    private IOrderService orderService;
    @Autowired
    private IProductStorageRelateService productStorageRelateService;

    @RequestMapping("/getProductStorageRelateListByTaskId/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProductStorageRelate>> getProductStorageRelateListByTaskId(@RequestParam("taskId") String taskId, @RequestParam("planId") String planId, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<ProductStorageRelate>> response = new JsonResponse<>();
        List<ProductStorageRelate> productStorageRelates = productStorageRelateService.getProductStorageRelateListByTaskId(taskId,planId);
        response.setResult(productStorageRelates);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/updateLockOnDutyProduct/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateLockOnDutyProduct(ProductStorageRelate productStorageRelates ,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productStorageRelateService.updateLockOnDutyProduct(productStorageRelates);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/deleteOnDutyProductCodeBox/{frontToken}")
    @ResponseBody
    public JsonResponse<String> deleteOnDutyProductCodeBox(ProductStorageRelate productStorageRelate ,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productStorageRelateService.deleteOnDutyProductCodeBox(productStorageRelate);
        return CommonUtil.getResponseData(response,result);
    }

    //现场报工
    @RequestMapping("/api/addBatchProductStorageRelates")
    @ResponseBody
    public JsonResponse<String> addBatchProductStorageRelates(@RequestBody List<ProductStorageRelate> productStorageRelates) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productStorageRelateService.addBatchProductStorageRelates(productStorageRelates);
        return CommonUtil.getResponseData(response,result);
    }

    //测试平库报工
    @RequestMapping("/api/addBatchProductStorageRelates1")
    @ResponseBody
    public JsonResponse<String> addBatchProductStorageRelates1(@RequestBody List<ProductStorageRelate> productStorageRelates) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productStorageRelateService.addBatchProductStorageRelates1(productStorageRelates);
        return CommonUtil.getResponseData(response,result);
    }
    @RequestMapping("/api/addTestBatchProductStorageRelates")
    @ResponseBody
    public JsonResponse<String> addTestBatchProductStorageRelates() throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        List<ProductStorageRelate> productStorageRelates1 = Lists.newArrayList();
        for(int i =0;i< 10;i++){
            ProductStorageRelate relate1 = new ProductStorageRelate();
            relate1.setTaskId("fbc89662pt-345cpt-4efapt-b1d1pt-8aad68aed893");
            relate1.setBoxCode("24000001");
            relate1.setUserName("陈工");
            relate1.setWhiteDay("1");
            relate1.setDutyDay("2024-05-18");
            productStorageRelates1.add(relate1);
        }
        String result = productStorageRelateService.addBatchProductStorageRelates(productStorageRelates1);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/api/updateStorageInAndOutBoxCodeStep1")
    @ResponseBody
    public JsonResponse<String> updateStorageInAndOutBoxCodeStep1() throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productStorageRelateService.updateStorageInAndOutBoxCodeStep1();
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/api/updateStorageInAndOutBoxCodeStep2")
    @ResponseBody
    public JsonResponse<String> updateStorageInAndOutBoxCodeStep2() throws Exception {
        JsonResponse<String> response = new JsonResponse<>();
        String result = productStorageRelateService.updateStorageInAndOutBoxCodeStep2();
        return CommonUtil.getResponseData(response, result);
    }
    //测试平库报工
    @RequestMapping("/api/addTestBatchProductStorageRelates1")
    @ResponseBody
    public JsonResponse<String> addTestBatchProductStorageRelates1() throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        List<ProductStorageRelate> productStorageRelates1 = Lists.newArrayList();
        String baseCode = "24239331";
        for(int i =0;i< 10;i++){
            ProductStorageRelate relate1 = new ProductStorageRelate();
//            relate1.setTaskId("fbc89662pt-345cpt-4efapt-b1d1pt-8aad68aed893");
            int number = Integer.parseInt(baseCode) + i;
            relate1.setBoxCode(String.valueOf(number));
            relate1.setUserName("测试平库wq");
            relate1.setGradeValue("长度130±2，内径6.0±0.2，壁厚0.28±0.05，切口角度50度±5，克重8.8克");
            relate1.setItemTypeId("单支连排");
//            relate1.setWhiteDay("1");
//            relate1.setDutyDay("2024-05-18");
            productStorageRelates1.add(relate1);
        }
        String result = productStorageRelateService.addBatchProductStorageRelates1(productStorageRelates1);
        return CommonUtil.getResponseData(response,result);
    }

    //规格下拉框
    @RequestMapping("/api/getOrderGradesByApp")
    @ResponseBody
    public JsonResponse<List<ProductStorageOutRelate>> getOrderGradesByApp(QueryForm queryForm) throws Exception{
        JsonResponse<List<ProductStorageOutRelate>> response = new JsonResponse<>();
        List<ProductStorageOutRelate> orders = orderService.getOrderGradesByApp(queryForm);
        response.setResult(orders);
        response.setSuccess(true);
        return response;
    }

    //规格模糊查询
    @RequestMapping("/api/getOrderGradesByAppMh")
    @ResponseBody
    public JsonResponse<List<ProductStorageRelate>> getOrderGradesByAppMh(QueryForm queryForm) throws Exception{
        JsonResponse<List<ProductStorageRelate>> response = new JsonResponse<>();
        List<ProductStorageRelate> orders = productStorageRelateService.getOrderGradesByAppMh(queryForm);
        response.setResult(orders);
        response.setSuccess(true);
        return response;
    }
}
